﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace GeneracListConsoleApp
{
    class Program
    {
        static void Main(string[] args)
        {
            GenericList<int> intList = new GenericList<int>();
            for(int i =0; i < 10; i++)
            {
                intList.Add(i);
            }
            //将求最大最小和求和放到lambda中
            IEnumerable<int> iterable = intList.ForEachGenericList(
                item =>
            {
                intList.Max = intList.Head.Data;
                intList.Min = intList.Head.Data;
                if (item.Data > intList.Max) //最大值
                {
                    intList.Max = item.Data;
                }
                if (item.Data < intList.Min)  //最小资
                {
                    intList.Min = item.Data;
                }
                intList.Sum += item.Data;
            });
            IEnumerator<int> iterator = iterable.GetEnumerator();
            Console.WriteLine("开始迭代");
            while (true)
            {
                Boolean result = iterator.MoveNext();
                if (!result)
                    break;
            }

            Console.WriteLine("最大值：" + intList.Max);
            Console.WriteLine("最小值：" + intList.Min);
            Console.WriteLine("求和：" + intList.Sum);
            Console.ReadLine();
        }
    }
}
